/* Copyright (c) 2007 Nordic Semiconductor. All Rights Reserved.
 *
 * The information contained herein is property of Nordic Semiconductor ASA.
 * Terms and conditions of usage are described in detail in NORDIC
 * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. 
 *
 * Licensees are granted free, non-transferable use of the information. NO
 * WARRENTY of ANY KIND is provided. This heading must NOT be removed from
 * the file.
 *
 * $LastChangedRevision: 2290 $
 */ 

/** @file
 * Interface functions for the SPI bus
 *
 * @author Ole Saether
 * @defgroup nordic_spi SPI HAL
 * @{
 * @ingroup nordic_hal
 * Interface functions for the SPI bus
 */
#ifndef HAL_SPI_H__
#define HAL_SPI_H__

#include <stdint.h>

/** Available SPI clock divide factors
 * The input argument of hal_spi_master_init must be defined in this @c enum
 */
typedef enum
{
    SPI_CLK_DIV2,       ///< CPU clock/2
    SPI_CLK_DIV4,       ///< CPU clock/4
    SPI_CLK_DIV8,       ///< CPU clock/8
    SPI_CLK_DIV16,      ///< CPU clock/16
    SPI_CLK_DIV32,      ///< CPU clock/32
    SPI_CLK_DIV64,      ///< CPU clock/64
    SPI_CLK_DIV128      ///< CPU clock/128
} hal_spi_clkdivider_t;

/** Function to initialize and enable the SPI master.
 */
void hal_spi_master_init(hal_spi_clkdivider_t ck);

/** Function to read/write a byte on the SPI master
 * This function writes the byte to the SPI master, then enters an infinite
 * loop waiting for the operation to finish. When the operation is finished
 * the SPI master interrupt bit is cleared and the received byte is returned.
 * @param b byte to write
 * @return The read byte
 */
uint8_t hal_spi_master_read_write(uint8_t b);

#endif // HAL_SPI_H__
/** @} */

